﻿using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.IO;

namespace GDIL1
{
    class Program
    {
        static void Main(string[] args)
        {
            //T2();
            //T3();
            T4();

            Console.WriteLine("done");

            Console.ReadKey();
        }

        static void T4()
        {
            Bitmap b = new Bitmap(500, 500);
            Graphics g = Graphics.FromImage(b);

            Pen p=new Pen(Color.Blue,1F);

            for (int i = 0; i < 90; i++)
            {
                g.RotateTransform(i);
                g.DrawLine(p,0,0,100,0);
                g.ResetTransform();
            }

            g.TranslateTransform(100,100);
            g.DrawLine(p,0,0,100,0);
            g.ResetTransform();

            g.TranslateTransform(100,200);
            for (int i = 0; i < 8; i++)
            {
                g.RotateTransform(45);
                g.DrawLine(p,0,0,100,0);
            }

            b.Save("./t4.png");
            b.Dispose();
            g.Dispose();
        }

        static void T3()
        {
            Bitmap b = new Bitmap(500, 500);
            Graphics g = Graphics.FromImage(b);
            Rectangle rect=new Rectangle(10,10,50,50);

            SolidBrush b1=new SolidBrush(Color.Blue);
            g.FillRectangle(b1,rect);

            g.DrawString("字符串",new Font("宋体",10),b1,new PointF(90,10) );

            TextureBrush b2=new TextureBrush(Image.FromFile(Path.GetFullPath("./a.jpg")));
            rect.Location=new Point(10,70);
            rect.Width = 200;
            rect.Height = 200;
            g.FillRectangle(b2,rect);

            rect.Location=new Point(10,290);
            LinearGradientBrush b3=new LinearGradientBrush(rect,Color.Yellow,Color.Black,LinearGradientMode.Horizontal);
            g.FillRectangle(b3,rect);

            b.Save("./t3.png");
            b.Dispose();
            g.Dispose();
        }

        static void T2()
        {
            Bitmap b = new Bitmap(500, 500);
            Graphics g = Graphics.FromImage(b);
            Pen p = new Pen(Color.Blue, 5F);
            p.DashStyle = DashStyle.Dot;
            g.DrawLine(p,10,10,200,10);

            p.DashPattern=new float[]{2,1};
            g.DrawLine(p,10,20,200,20);

            p.DashStyle = DashStyle.Solid;
            p.EndCap = LineCap.ArrowAnchor;
            g.DrawLine(p,10,30,200,30);

            b.Save("./t2.png");
            b.Dispose();
            g.Dispose();
        }

        static void T1()
        {
            Bitmap b = new Bitmap(200, 200);
            Graphics g = Graphics.FromImage(b);
            Pen p = new Pen(Color.Blue, 2F);
            g.DrawLine(p, 10, 10, 100, 100);
            g.DrawRectangle(p, 10, 10, 100, 100);
            g.DrawEllipse(p, 10, 10, 100, 100);
            b.Save("./t1.png");
            b.Dispose();
            g.Dispose();
        }
    }
}
